#include "Config.h"
#include "Led.h"

unsigned int Sys_min = 0;
unsigned char Sys_s = 0;
unsigned int Sys_ms = 0;
unsigned int Sys_us = 0;

void SysTick_init(void)
{
	SysTick_Config(SystemCoreClock / 1000000);  //1 - 1s  1000 - 1ms  1000000 - 1us
}

void Usr_sys_timer(void)
{
	timer_cnt_us();
}

void timer_cnt_us(void)
{
	Sys_us ++;
	
	if(Sys_us >= 1000)
	{
		Sys_us = 0;
		timer_cnt_ms();
	}
}

void timer_cnt_ms(void)
{
	Sys_ms ++;
	
	if(Sys_ms >= 1000)
	{
		Sys_ms = 0;
		timer_cnt_s();
	}
}

void timer_cnt_s(void)
{
	Sys_s ++;
	
	if(Sys_s >= 60)
	{
		Sys_s = 0;
		Sys_min ++;
	}
	
	set_led(1-led_state);
}
